<include file="../Public/_header" />
<script type="text/javascript">
//鼠标移动表格效果
$(document).ready(function(){
    $("tr[overstyle='on']").hover(
      function () {
        $(this).addClass("bg_hover");
      },
      function () {
        $(this).removeClass("bg_hover");
      }
    );
});

function setStatus(id, status) {
	$.post("{:U('admin/Plugin/doSetMedalStatus')}",{id:id,status:status},function(res){
		if(res=='1') {
			ui.success('保存成功');
			
			var statusArray = new Array("关闭","开启");
			$('#status_'+id).html("已"+statusArray[status]);
			statusArray[status] = '';
			var html = '';
			for (s in statusArray) {
				if(statusArray[s]=='') continue;
				html += '<a href="javascript:void(0);" onclick="setStatus('+id+','+s+')">设为'+statusArray[s]+'</a> ';
			}
			$('#setStatus_'+id).html(html);
		}else {
			ui.error('保存失败');
		}
	});
}

function move(id, direction) {
	var baseid  = direction == 'up' ? $('#'+id).prev().attr('id') : $('#'+id).next().attr('id');
    if(!baseid) {
        direction == 'up' ? ui.error('已经是最前面了') : ui.error('已经是最后面了');
    }else {
        $.post("{:U('admin/Plugin/doMedalOrder')}", {id:id, baseid:baseid}, function(res){
            if(res == '1') {
                //交换位置
                direction == 'up' ? $('#'+id).insertBefore('#'+baseid) : $("#"+id).insertAfter('#'+baseid);
                ui.success('保存成功');
            }else {
                ui.error('保存失败');
            }
        });
    }
}
</script>
<div class="so_main">
  <div class="page_tit">勋章列表</div>
  <div class="Toolbar_inbox">
    <a href="{:U('admin/Plugin/installMedal')}" class="btn_a"><span>安装勋章</span></a>
  </div>
  <div class="list">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th class="line_l">ID</th>
    <th class="line_l">路径名称</th>
    <th class="line_l">勋章名称</th>
    <th class="line_l">状态</th>
    <th class="line_l">状态设置</th>
    <th class="line_l">排序</th>
    <th class="line_l">操作</th>
  </tr>
  
  <php>if(empty($medal)) {</php>
    <tr><td>暂无待安装应用</td></tr>
  <php>}</php>
  
  <volist id="vo" name="medal">
      <tr overstyle='on' id="{$vo['medal_id']}">
        <td>{$vo['medal_id']}</td>
        <td>{$vo['path_name']}</td>
        <td>{$vo['title']}</td>
        <td id="status_{$vo['medal_id']}"><php>echo $vo['is_active'] ? '已开启' : '已关闭'</php></td>
        <td id="setStatus_{$vo['medal_id']}">
            <php>if($vo['is_active']){</php>
            <a href="javascript:void(0);" onclick="setStatus('{$vo['medal_id']}','0');">设为关闭</a>
            <php>}else {</php>
            <a href="javascript:void(0);" onclick="setStatus('{$vo['medal_id']}','1');">设为开启</a>
            <php>}</php>
        </td>
        <td>
            <a href="javascript:void(0)" class="ico_top" onclick="move('{$vo['medal_id']}','up');"><img src="__PUBLIC__/admin/images/zw_img.gif"></a>&nbsp;&nbsp;
            <a href="javascript:void(0)" class="ico_btm" onclick="move('{$vo['medal_id']}','down');"><img src="__PUBLIC__/admin/images/zw_img.gif"></a>
        </td>
        <td>
            <php>
	        $uninstall_href = U('admin/Plugin/uninstallMedal',array('medal_id'=>$vo['medal_id']));
	        $uninstall_alert_1 = '卸载程序将会移除所有的数据，且无法恢复，确定继续?';
	        $uninstall_alert_2 = '卸载后, 您将丢失所有的数据, 强烈建议您备份数据库后再卸载!! 确定继续?';
	        </php>
            <a href="javascript:void(0);" onclick="if(confirm('{$uninstall_alert_1}') && confirm('{$uninstall_alert_2}')) location.href='{$uninstall_href}';return false;">卸载</a>
        </td>
      </tr>
  </volist>
  </table>
  </div>
  <div class="Toolbar_inbox">
    <a href="{:U('admin/Plugin/installMedal')}" class="btn_a"><span>安装勋章</span></a>
  </div>
</div>
<include file="../Public/_footer" />